package skiplist;

import tools.Asserts;
import tools.Times;

import java.util.TreeMap;

/**
 * @Author: LDeng
 * @Date: 2021-05-05 14:33
 */
public class Main {

    public static void main(String[] args) {
        SkipList<Integer,Integer> list=new SkipList<>();
        TreeMap<Integer,Integer> map=new TreeMap<>();
 //       test(list,20,5);
//
        int count = 200_00;
        int delta = 10;

		Times.test("SkipList", () -> {
			test(list, count, delta);
		});

        Times.test("TreeMap", () -> {
            test(map, count, delta);
        });
    }

    private static void test(SkipList<Integer, Integer> list, int count, int delta) {
        for (int i = 0; i < count; i++) {
            list.put(i, i + delta);
        }
		//System.out.println(list);
        for (int i = 0; i < count; i++) {
            Asserts.test(list.get(i) == i + delta);
        }
        Asserts.test(list.size() == count);
//        System.out.println("debug: listsize=>"+list.size);
        for (int i = 0; i < count; i++) {
            Asserts.test(list.remove(i) == i + delta);
        }
        Asserts.test(list.size() == 0);
    }

    private static void test(TreeMap<Integer, Integer> map, int count, int delta) {
        for (int i = 0; i < count; i++) {
            map.put(i, i + delta);
        }
        for (int i = 0; i < count; i++) {
            Asserts.test(map.get(i) == i + delta);
        }
        Asserts.test(map.size() == count);
        for (int i = 0; i < count; i++) {
            Asserts.test(map.remove(i) == i + delta);
        }
        Asserts.test(map.size() == 0);
    }

}
